package com.paipaideli.ui.mine.head;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alipay.sdk.app.PayTask;
import com.jakewharton.rxbinding2.view.RxView;
import com.paipaideli.R;
import com.paipaideli.common.base.BasePresenterActivity;
import com.paipaideli.common.http.Api;
import com.paipaideli.common.pullrefresh.TStatusView;
import com.paipaideli.common.utils.StringUtil;
import com.paipaideli.common.utils.ToastUtil;
import com.paipaideli.common.utils.preferrnces.FastData;
import com.paipaideli.ui.pay.PayActivity;

import org.json.JSONObject;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.android.schedulers.AndroidSchedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by 充值
 */
public class InvestActivity extends BasePresenterActivity {

    private static final int SDK_PAY_FLAG = 1;

    Unbinder unbinder;
    @BindView(R.id.top_back)
    RelativeLayout top_back;
    @BindView(R.id.top_title)
    TextView top_title;
    @BindView(R.id.et_invest_money)
    EditText etInvestMoney;
    @BindView(R.id.btn_invest)
    Button btnInvest;
    @BindView(R.id.bg_statusview)
    TStatusView bg_statusview;

    private String money;

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @SuppressWarnings("unused")
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SDK_PAY_FLAG: {
                    finish();
                    break;
                }
                default:
                    break;
            }
        }

        ;
    };

    @Override
    public int getContentView() {
        return R.layout.activity_invest;
    }

    @Override
    public void initView() {
        unbinder = ButterKnife.bind(this);
        top_title.setText("充值");
        //返回
        top_back.setOnClickListener(o ->
                finish()
        );

        //去充值
        addDisposable(RxView.clicks(btnInvest)
                .throttleFirst(1, TimeUnit.SECONDS)
                .subscribe(o -> {
                    money = etInvestMoney.getText().toString().trim();
                    if (!StringUtil.isEmpty(money)) {
                        Intent intent = new Intent(InvestActivity.this,PayActivity.class);
                        intent.putExtra("which","2");
                        intent.putExtra("amount",money);
                        startActivity(intent);
                    } else {
                        ToastUtil.show("请输入您要充值的金额！");
                    }
                }));
    }

}
